package com.dianping.cat.consumer.storage.model.transform;

import com.dianping.cat.consumer.storage.model.IEntity;
import com.dianping.cat.consumer.storage.model.IVisitor;
import com.dianping.cat.consumer.storage.model.entity.Domain;
import com.dianping.cat.consumer.storage.model.entity.Machine;
import com.dianping.cat.consumer.storage.model.entity.Operation;
import com.dianping.cat.consumer.storage.model.entity.Segment;
import com.dianping.cat.consumer.storage.model.entity.Sql;
import com.dianping.cat.consumer.storage.model.entity.StorageReport;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  16 */   private Stack<Object> m_objs = new Stack();

  private StorageReport m_storageReport;


  public DefaultMerger() {}

  public DefaultMerger(StorageReport storageReport) {
    this.m_storageReport = storageReport;
    this.m_objs.push(storageReport);
  }


  public StorageReport getStorageReport() { return this.m_storageReport; }



/*  33 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  37 */     this.m_objs.push(to);
/*  38 */     from.accept(this);
/*  39 */     this.m_objs.pop();
  }


/*  43 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  47 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }



/*  51 */   protected void mergeOperation(Operation to, Operation from) { to.mergeAttributes(from); }



/*  55 */   protected void mergeSegment(Segment to, Segment from) { to.mergeAttributes(from); }



/*  59 */   protected void mergeSql(Sql to, Sql from) { to.mergeAttributes(from); }


  protected void mergeStorageReport(StorageReport to, StorageReport from) {
/*  63 */     to.mergeAttributes(from);
/*  64 */     to.getIds().addAll(from.getIds());
/*  65 */     to.getIps().addAll(from.getIps());
/*  66 */     to.getOps().addAll(from.getOps());
  }


  public void visitDomain(Domain from) {
/*  71 */     Domain to = (Domain)this.m_objs.peek();

/*  73 */     mergeDomain(to, from);
/*  74 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
    for (Operation source : from.getOperations().values()) {
/*  79 */       Operation target = to.findOperation(source.getId());

/*  81 */       if (target == null) {
/*  82 */         target = new Operation(source.getId());
/*  83 */         to.addOperation(target);
      }

/*  86 */       this.m_objs.push(target);
/*  87 */       source.accept(this);
/*  88 */       this.m_objs.pop();
    }

/*  91 */     for (Sql source : from.getSqls().values()) {
/*  92 */       Sql target = to.findSql(source.getId());

/*  94 */       if (target == null) {
/*  95 */         target = new Sql(source.getId());
/*  96 */         to.addSql(target);
      }

/*  99 */       this.m_objs.push(target);
/* 100 */       source.accept(this);
/* 101 */       this.m_objs.pop();
    }
  }


  public void visitMachine(Machine from) {
/* 107 */     Machine to = (Machine)this.m_objs.peek();

/* 109 */     mergeMachine(to, from);
/* 110 */     visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/* 114 */     for (Domain source : from.getDomains().values()) {
/* 115 */       Domain target = to.findDomain(source.getId());

/* 117 */       if (target == null) {
/* 118 */         target = new Domain(source.getId());
/* 119 */         to.addDomain(target);
      }

/* 122 */       this.m_objs.push(target);
/* 123 */       source.accept(this);
/* 124 */       this.m_objs.pop();
    }
  }


  public void visitOperation(Operation from) {
/* 130 */     Operation to = (Operation)this.m_objs.peek();

/* 132 */     mergeOperation(to, from);
/* 133 */     visitOperationChildren(to, from);
  }

  protected void visitOperationChildren(Operation to, Operation from) {
/* 137 */     for (Segment source : from.getSegments().values()) {
/* 138 */       Segment target = to.findSegment(source.getId());

/* 140 */       if (target == null) {
/* 141 */         target = new Segment(source.getId());
/* 142 */         to.addSegment(target);
      }

/* 145 */       this.m_objs.push(target);
/* 146 */       source.accept(this);
/* 147 */       this.m_objs.pop();
    }
  }


  public void visitSegment(Segment from) {
/* 153 */     Segment to = (Segment)this.m_objs.peek();

/* 155 */     mergeSegment(to, from);
/* 156 */     visitSegmentChildren(to, from);
  }


  protected void visitSegmentChildren(Segment to, Segment from) {}


  public void visitSql(Sql from) {
/* 164 */     Sql to = (Sql)this.m_objs.peek();

/* 166 */     mergeSql(to, from);
/* 167 */     visitSqlChildren(to, from);
  }


  protected void visitSqlChildren(Sql to, Sql from) {}


  public void visitStorageReport(StorageReport from) {
/* 175 */     StorageReport to = (StorageReport)this.m_objs.peek();

/* 177 */     mergeStorageReport(to, from);
/* 178 */     visitStorageReportChildren(to, from);
  }

  protected void visitStorageReportChildren(StorageReport to, StorageReport from) {
/* 182 */     for (Machine source : from.getMachines().values()) {
/* 183 */       Machine target = to.findMachine(source.getId());

/* 185 */       if (target == null) {
/* 186 */         target = new Machine(source.getId());
/* 187 */         to.addMachine(target);
      }

/* 190 */       this.m_objs.push(target);
/* 191 */       source.accept(this);
/* 192 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/storage/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */